package com.fuluwa.domain.bank.model;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.fuluwa.domain.bank.model.TransactionLog.TransactionType;
import com.fuluwa.domain.security.model.User;
import com.fuluwa.domain.shared.AbstractIdDomainObject;

/**
 * Define the funds details,each fund change will have a record.for query.
 * @author yongxia
 *
 */
@Entity
@Table(name = "b_nobook")
public class Nobook extends AbstractIdDomainObject {
	public static enum NobookType{
		CREDIT,DEBIT
	}
	@ManyToOne
	@JoinColumn(name = "cod_acct")
	private Account account;

	@ManyToOne
	@JoinColumn(name = "cod_user")
	private User user;

	private String txnDesc;

	@Column(name = "amount", columnDefinition = "decimal(13,2)")
	private BigDecimal txnAmount;

	@Column(name = "val", columnDefinition = "decimal(13,2)")
	private BigDecimal balance;
	
	@Enumerated(EnumType.STRING)
	private NobookType type;
	
	@Enumerated(EnumType.STRING)
	private TransactionType transactionType;

	private Bank bank = Bank.getDefaultBank();

	@Temporal(TemporalType.DATE)
	@Column(name = "dat_post")
	private Date postDate = new Date();

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "tim_post")
	private Date postTime = new Date();

	private Nobook() {
	}
	public Nobook(Account account,  String txnDesc, BigDecimal txnAmount, NobookType type,TransactionType transactionType) {
		this.account = account;
		this.user = account.getUser();
		this.txnDesc = txnDesc;
		this.txnAmount = txnAmount;
		this.balance = account.getAvailableBalance();
		this.type = type;
		this.transactionType=transactionType;
	}

	public Account getAccount() {
		return account;
	}

	public User getUser() {
		return user;
	}

	public String getTxnDesc() {
		return txnDesc;
	}

	public BigDecimal getTxnAmount() {
		return txnAmount;
	}

	public BigDecimal getBalance() {
		return balance;
	}

	public Bank getBank() {
		return bank;
	}

	public Date getPostDate() {
		return postDate;
	}

	public Date getPostTime() {
		return postTime;
	}

	public NobookType getType() {
		return type;
	}

	@Override
	public String toString() {
		return "Nobook [account=" + account.getAccountNo() + ", user=" + user.getLoginName() + ", txnDesc=" + txnDesc + ", txnAmount=" + txnAmount
				+ ", balance=" + balance + ", type=" + type + ", bank=" + bank + ", postDate=" + postDate
				+ ", postTime=" + postTime + "]";
	}
	
	

}
